<?php
require_once("vcl/vcl.inc.php");
require_once("lib/db_connection.php");
//Includes
use_unit("components4phpfull/jtsitetheme.inc.php");
use_unit("platinumgrid/jtplatinumgrid.inc.php");
use_unit("forms.inc.php");
use_unit("extctrls.inc.php");
use_unit("stdctrls.inc.php");

//Class definition
class frame_tire_history extends Page
{
       public $btnSearch = null;
       public $btnPrint = null;
       public $edtSearch = null;
       public $hfSearch = null;
       public $hiddenVin = null;
       public $JTSiteTheme1 = null;
       public $JTTireJournal = null;
       function btnPrintJSMouseOut($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnPrint'].src="image/btn_print.png"
       <?php

       }

       function btnPrintJSMouseOver($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.images['btnPrint'].src="image/btn_print2.png"
       <?php

       }

       function btnPrintJSClick($sender, $params)
       {

       ?>
       var height = 1000;
       var width = 850;
       var left = Math.floor((screen.availWidth/2) - (width/2));
       var top = Math.floor((screen.availHeight/2) - (height/2));
       var veh = document.getElementById('hiddenVin').value;
       window.open('print_tire_history.php?veh='+veh,'popup','width='+width+',height='+height+',top='+top+',left='+left+',scrollbars=yes,resizable=no,toolbar=no,directories=no,location=no,menubar=no,status=no');
       <?php

       }



       function edtSearchJSClick($sender, $params)
       {

       ?>
       //Add your javascript code here
       document.getElementById('edtSearch').value = '';
       <?php

       }

       function btnSearchJSClick($sender, $params)
       {

       ?>
       var search = document.getElementById('edtSearch').value;
       var veh = document.getElementById('hiddenVin').value;
       document.location.href = "frame_tire_history.php?search="+search+"&veh="+veh;
       <?php

       }

       function frame_tire_historyCreate($sender, $params)
       {
       $search = $_GET['search'];
       $vin = $_GET['veh'];
       if($search!=null || $search!='')
       {
       $this->hfSearch->setValue($search);
       $this->edtSearch->setText($search);
       }
       else
       {
       $this->edtSearch->Text = '';
       $this->hfSearch->setValue('');
       }
       if($vin!=null || $vin!='')
       {
        $this->hiddenVin->setValue($vin);
       }

       }


       function JTTireJournalShow($sender, $params)
       {
       $jou_arr = array();
       $search = $this->hfSearch->getValue();
       $query_journal = "SELECT tire_id, location, description, axle, wheel, tread, date, comments FROM tire_srvcejournal_tbl
       WHERE vehicle_id='".$this->hiddenVin->getValue()."'
       AND (location LIKE '%".$search."%'
       OR description LIKE '%".$search."%'
       OR axle LIKE '%".$search."%'
       OR wheel LIKE '%".$search."%'
       OR tread LIKE '%".$search."%'
       OR date LIKE '%".$search."%'
       OR comments LIKE '%".$search."%')
       ORDER BY journal_id  DESC";
       $result_journal = mysql_query($query_journal) or die('LIST JOURNAL '.mysql_error());

       while($row_journal = mysql_fetch_array($result_journal))
       {

        $tire_id = $row_journal['tire_id'];

        $query_tire = "SELECT * FROM tire_inventory_tbl WHERE tire_id='".$tire_id."'";
        $result_tire = mysql_query($query_tire) or die('select tire'.mysql_error());
        $row_tire = mysql_fetch_array($result_tire);

        $jou_arr[] = array(
        'Date'=> $row_journal['date'],
        'Description'=> $row_journal['description'],
        'Brand'=> $row_tire['manufacturer'],
        'Position'=> $row_journal['location'],
        'Remarks'=> $row_journal['comments']
        );
       }
       $this->JTTireJournal->setCellData($jou_arr);


       }
}

global $application;

global $frame_tire_history;

//Creates the form
$frame_tire_history=new frame_tire_history($application);

//Read from resource file
$frame_tire_history->loadResource(__FILE__);

//Shows the form
$frame_tire_history->show();

?>